package com.lmq.ocp.pro;

public class Ocp {
    public static void main(String[] args) {
        // test
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawSahpe(new Rectangle());
        graphicEditor.drawSahpe(new Circle());
        graphicEditor.drawSahpe(new Triangle());


    }
}
//绘图类
// 违反OCP原则
// 新增加图形，修改地方较多

class GraphicEditor{
    public void drawSahpe(Shape s){
        s.draw();
    }

}

abstract class Shape{
    int m_type;
    public abstract void draw();

}

class Rectangle extends Shape{
    Rectangle(){
        super.m_type = 1;
    }

    @Override
    public void draw() {
        System.out.println("drawing Rectangle!!!");

    }
}

class Circle extends Shape{
    Circle(){
        super.m_type = 2;
    }

    @Override
    public void draw() {
        System.out.println("drawing Circle!!!");
    }
}


class Triangle extends  Shape{
    Triangle(){
        super.m_type = 3;
    }

    @Override
    public void draw() {
        System.out.println("drawing Triangle!!!");

    }
}